﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Practices.EnterpriseLibrary.Data;
using System.Data.Common;
using System.Data;

namespace SampleSite.DataAccess
{
	internal class ExceptionLogDA
	{
		internal bool AddExceptionLog(string Message, string Source, string StackTrace, string Description)
		{
			Database db = DatabaseFactory.CreateDatabase();
			string sqlCommand = "INSERT INTO ExceptionLog (Message,Source,StackTrace,Description) VALUES (@Message,@Source,@StackTrace,@Description)";
			DbCommand dbCommand = db.GetSqlStringCommand(sqlCommand);
			db.AddInParameter(dbCommand, "@Message", DbType.String, Message);
			db.AddInParameter(dbCommand, "@Source", DbType.String, Source);
			db.AddInParameter(dbCommand, "@StackTrace", DbType.String, StackTrace);
			db.AddInParameter(dbCommand, "@Description", DbType.String, Description);
			try
			{
				int r = (int)db.ExecuteNonQuery(dbCommand);
				return r == 1;
			}
			catch (Exception ex)
			{
				return false;
			}
		}

	}
}
